package io.adrainty.algorithm.utils;

import java.util.Random;

/**
 * <p>ArrayUtils</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description ArrayUtils
 * @since 2025/7/28 11:15:55
 */
public class ArrayUtils {

    private static final Random random = new Random();

    private ArrayUtils() {}

    /**
     * 生成随机数组
     * @param length 数组长度
     * @return 随机数组
     */
    public static int[] generateArray(int length) {
        int[] array = new int[length];
        for (int i = 0; i < length; i++) {
            int nextInt = random.nextInt(0, 100);
            array[i] = nextInt;
        }
        return array;
    }

    /**
     * 交换数组元素
     * @param arr 数组
     * @param i 索引1
     * @param j 索引2
     */
    public static void swap(int[] arr, int i, int  j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

}
